#include <bits/stdc++.h>
using namespace std;

class Solution {
public:
    string simplifyPath(string path) {
        vector<string> tmp;
        int n = path.size();
        for(int i=0; i<n; ++i){
            while(i<n && path[i]=='/') ++i;
            if(i==n) break;
            string subpath;
            while(i<n && path[i]!='/') subpath+=path[i++];
            if(subpath == ".." && !tmp.empty()) tmp.pop_back();
            else if(subpath != "." && subpath!="..") tmp.emplace_back(subpath);
        }
        string ans;
        for(auto& subpath:tmp){
            ans+='/';
            ans+=subpath;
        }
        if(tmp.empty()) ans+='/';
        return ans;
    }
};

int main(){

}